package StackAndQueue;

import java.util.*;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class maxSlidingWindow {
    public int[] maxSlidingWindow(int[] nums, int k) {
        if (nums.length == 1){
            return nums;
        }
        int len = nums.length - k + 1;
        int[] res = new int[len];
        int num = 0;
        MyQuene2 myQuene2 = new MyQuene2();
        for (int i = 0; i < k; i++) {
            myQuene2.add(nums[i]);
        }
        res[num++] = myQuene2.peek();
        for (int i = k; i < nums.length; i++) {
            myQuene2.poll(nums[i - k]);
            myQuene2.add(nums[i]);
            res[num++] = myQuene2.peek();
        }
        return res;
    }
}
